package week14_database;

import java.util.List;

public class TestMain {

	/**
	 * 15,16,17行分别使用了不同的实现
	 * @param args
	 */
	public static void main(String[] args) {
		Student[] students = new Student[4];
		students[0] = new Student(1,"小名");
		students[1]= new Student(2,"小红");
		students[2] = new Student(3,"曹二");
		students[3] = new Student(4,"张三");
		//StudentDao sdm = new StudentDaoArrayImpl(50);//使用数组实现
		//StudentDao sdm = new StudenDaoListImpl();//使用列表实现
		StudentDao sdm = new StudentDaoJDBCImpl();
		//System.out.println(sdm.add(new Student(1,"zhansan")));
		//下面的代码，无需关心后台到底是文件、数据库、数组、List
		//因为这里是面向StudentDao接口进行编程,所以不管上面怎么修改，下面代码可以不用改动
		/*System.out.println("===========写入学生========");
		for(Student e:students){
			int i=sdm.add(e);
			if(i==0){
				System.out.println("添加学生失败");
			}else{
				System.out.println("插入成功！！");
			}
		}*/
		/*System.out.println("===========显示所有学生========");
		List<Student> list =sdm.findAll();
		for (Student s : list) {
			System.out.println("id="+s.getId()+"  name="+s.getName());
		}
		System.out.println("===========查询学生========");
		Student temp = sdm.findById("4") ;
		if(temp == null){
			System.out.println("查无此人");
		}else{
			System.out.println("id="+temp.getId()+"  name="+temp.getName());
		}
		list=sdm.findByName("小");
		if(list!=null)
		for (Student s : list) {
			System.out.println("id="+s.getId()+"  name="+s.getName());
		}
		else
			System.out.println("查不到");*/
	/*	System.out.println("===========修改学生========");
		int k=sdm.update(new Student(1,"陈三"));
		if(k!=0)
			System.out.println("修改成功");
		else
			System.out.println("修改不成功");*/
		
		System.out.println("===========删除学生========");
		int k=sdm.delete(1);
		if(k!=0)
			System.out.println("删除成功");
		else
			System.out.println("删除不成功");
	}

}
